﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Oracle.DataAccess.Client;
using System.Configuration;

namespace Testify.Tools
{
    public partial class Security : System.Web.UI.Page
    {
       
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnShowInsert_onClick(object sender, EventArgs e)
        {
           // this.gdvSecurity.FooterRow.Visible = true;
           this.gdvSecurity.FooterRow.FindControl("btnShowInsertFoot").Visible = false;
           this.gdvSecurity.FooterRow.FindControl("btnInsert").Visible = true;
           this.gdvSecurity.FooterRow.FindControl("btnCancelInsert").Visible = true;
           this.gdvSecurity.FooterRow.FindControl("txtNewName").Visible = true;
           this.gdvSecurity.FooterRow.FindControl("ddlNewUserType").Visible = true;
        }

        protected void btnInsert_onClick(object sender, EventArgs e)
        {
            OracleConnection myConnection1 = new OracleConnection(ConfigurationManager.ConnectionStrings["Singularity"].ConnectionString);
            OracleCommand cmdAdd = new OracleCommand("SECURITIES.createPagePermissions", myConnection1);
            cmdAdd.CommandType = CommandType.StoredProcedure;
            cmdAdd.BindByName = true;

            try
            {
                myConnection1.Open();

                cmdAdd.Parameters.Clear();
                cmdAdd.Parameters.Add("p_PageName", (this.gdvSecurity.FooterRow.FindControl("txtNewName") as TextBox).Text);
                cmdAdd.Parameters.Add("p_PermissionLevel", (this.gdvSecurity.FooterRow.FindControl("ddlNewUserType") as DropDownList).SelectedValue.ToString());
                cmdAdd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
               Utilities.logError(Page.Title, ex);
            }
            finally
            {
                myConnection1.Close();
            }

            this.gdvSecurity.FooterRow.Visible = false;
            this.gdvSecurity.DataBind();
        }

        protected void btnCancelInsert_onClick(object sender, EventArgs e)
        {
            //this.gdvSecurity.FooterRow.Visible = false;
           this.gdvSecurity.FooterRow.FindControl("btnShowInsertFoot").Visible = true;
           this.gdvSecurity.FooterRow.FindControl("btnInsert").Visible = false;
           this.gdvSecurity.FooterRow.FindControl("btnCancelInsert").Visible = false;
           this.gdvSecurity.FooterRow.FindControl("txtNewName").Visible = false;
           this.gdvSecurity.FooterRow.FindControl("ddlNewUserType").Visible = false;
        }

        protected void update(object sender, SqlDataSourceCommandEventArgs e)
        {
            OracleConnection myConnection1 = new OracleConnection(ConfigurationManager.ConnectionStrings["Singularity"].ConnectionString);
            OracleCommand cmdSet = new OracleCommand("SECURITIES.setPagePermissions", myConnection1);
            cmdSet.CommandType = CommandType.StoredProcedure;
            cmdSet.BindByName = true;

            try
            {
                myConnection1.Open();
                cmdSet.Parameters.Clear();
                cmdSet.Parameters.Add("p_SecurityID", e.Command.Parameters["security_id"].Value.ToString());
                cmdSet.Parameters.Add("p_PermissionLevel", e.Command.Parameters["PERMISSION_LEVEL"].Value.ToString());
                cmdSet.ExecuteNonQuery();
            }
            catch (Exception)
            {

            }
            finally
            {
                myConnection1.Close();
            }

            e.Cancel = true;
        }
    }
}